package tests;

import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import junit.framework.TestCase;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.web.servlet.ModelAndView;
import web.WebcalendarController;
import bus.UserManager;
import bus.User;

public class TestWebcalendarController extends TestCase {

    private ApplicationContext ac;

    public void setUp() throws IOException {
        ac = new FileSystemXmlApplicationContext("src/tests/WEB-INF/webcalendar-servlet.xml");
    }

    public void testHandleRequest() throws ServletException, IOException {
        WebcalendarController sc = (WebcalendarController) ac.getBean("webcalendarController");
        ModelAndView mav = sc.handleRequest((HttpServletRequest) null, (HttpServletResponse) null);
        Map m = mav.getModel();
        List pl = (List) ((Map) m.get("model")).get("users");
        User p1 = (User) pl.get(0);
        assertEquals("corey", p1.getUsername());
    }
}